package org.hxzon.workeasy.pages.file;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.workeasy.model.base.Upload;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.permissions.FileCRPermissions;
import org.hxzon.workeasy.service.EasyFileService;

public class DownloadFile extends MyBasePage {
    @Inject
    private EasyFileService fileSer;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object download(String id) {
        new FileCRPermissions().check(null, getVisitor());
        Upload upload = fileSer.findById(id);
        return getWebUtil().download(upload);
    }
}
